package com.supermali.entity.npc.monistor;

import com.supermali.behavior.Gravity;
import com.supermali.behavior.move.land.MonitorMove;
import com.supermali.creater.MapCreater;
import com.supermali.entity.MapImageAbstract;
import com.supermali.entity.npc.IntesectDirect;
import com.supermali.entity.npc.NPCAbstract;

import java.util.List;
import java.util.Set;

/**
 * @project super-mali
 * @Date 2021/2/28
 * @Auth yangrui
 **/
public abstract class MonistorAbstract extends NPCAbstract {

    private Gravity gravity;
    // 移动
    MonitorMove monitorMove;
    public MonistorAbstract(Double x, Double y, MapCreater mapCreater) {
        super(x, y, mapCreater);
        gravity = new Gravity(this);
        monitorMove = new MonitorMove(this);
        monitorMove.start();
    }

    @Override
    public Set<IntesectDirect> checkCollide() {
        Set<IntesectDirect> intesectDirects = super.checkCollide();
        reverseVDirect(intesectDirects);
        return intesectDirects;
    }

    @Override
    public void destroy(long delta) {
//        super.destroy(delta);
        List<MapImageAbstract> removes = getMapCreater().getRemoves();
        removes.add(this);
    }

    /**
     * 怪物的默认移动方式
     * */
    @Override
    public void proccessData(long delta) {
        getGravity().autoDown();
        if(!monitorMove.isOver()) {
            monitorMove.move(delta);
        }
    }

    /**
     * 翻转怪物的速度方向
     * */
    public void reverseVDirect(Set<IntesectDirect> intesectDirects){
        for(IntesectDirect direct: intesectDirects){
            if(direct.getDirect()== IntesectDirect.Direct.LEFT){
                monitorMove.setXdirect(-1);
            }else if(direct.getDirect()== IntesectDirect.Direct.RIGHT){
                monitorMove.setXdirect(1);
            }
        }
    }


    public Gravity getGravity() {
        return gravity;
    }

    public MonitorMove getMonitorMove() {
        return monitorMove;
    }

}
